home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / ast_comp / sql.txt / parser.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-04  |  2.2 KB  |  142 lines

  1. /*
  2. Parser
  3. Version 1.0
  4. 1986 Columbia Union College
  5. By Leroy G. Cain
  6. */
  7.  
  8. # include "ddf.h"
  9. # include <stdio.h>
  10. # define U(x) x
  11.  
  12. static char     *par_buf;
  13. static char     *par_sbuf;
  14.  
  15. extern char *yysptr, yysbuf[];
  16. extern int yytchar;
  17. extern int yylineno;
  18. extern int ddf_err;
  19.  
  20. static unsigned char    ptree[4096];
  21. static unsigned char    *ptree_ptr;
  22.  
  23. parse ( ddf_run, str )
  24. DDFRUN  *ddf_run;
  25. char    *str;
  26. {
  27. register int    preturn;
  28. int     fd;
  29.  
  30.         par_buf = str;
  31.         par_sbuf = str;
  32.         ptree_ptr = ptree;
  33.         preturn = yyparse();
  34.         ddf_run->par_buf = ptree;
  35.         ddf_run->buf_len = ptree_ptr-ptree;
  36.         return !preturn;
  37.         /*
  38.         if( (preturn=ddf_parser()) && type >0 )
  39.                 pcovert(ptree,type);
  40.         return preturn;
  41.         */
  42. }
  43.  
  44. input()
  45. {
  46.         return
  47.         (
  48.                 ( ( yytchar = ( yysptr > yysbuf ? U(*--yysptr) : *par_buf++ )
  49. )
  50.                 == 10 ? (yylineno++, yytchar) : yytchar) == '\0' ? 0 :
  51. yytchar
  52.         );
  53. }
  54.  
  55. unput(c)
  56. int     c;
  57. {
  58.         yytchar = c;
  59.         if (yytchar=='\n') yylineno--;
  60.         *yysptr++ = yytchar;
  61. }
  62.  
  63. output(c)
  64. int     c;
  65. {
  66. }
  67.  
  68. parerror(err)
  69. int     err;
  70. {
  71.         ddf_err=err;
  72. }
  73.  
  74. putvar(s)
  75. char    *s;
  76. {
  77. int     x;
  78.  
  79.         *ptree_ptr++ = strlen(s);
  80.         for(;*s;*ptree_ptr++ = *s++);
  81. }
  82.  
  83. putstr(s)
  84. char    *s;
  85. {
  86. int     x;
  87.  
  88.         *ptree_ptr++ = x = strlen(s)-2;
  89.         *(s+x+1)= '\0';
  90.         for(s++;*s;*ptree_ptr++ = *s++);
  91. }
  92.  
  93. puttok(n)
  94. int     n;
  95. {
  96.         *ptree_ptr++ = n;
  97. }
  98.  
  99. putint(s)
  100. char    *s;
  101. {
  102. union
  103. {
  104.         long    num;
  105.         unsigned char   n[4];
  106. } cludge;
  107.  
  108.         cludge.num = atoi(s);
  109.         *ptree_ptr++ = cludge.n[0];
  110.         *ptree_ptr++ = cludge.n[1];
  111.         *ptree_ptr++ = cludge.n[2];
  112.         *ptree_ptr++ = cludge.n[3];
  113. }
  114.  
  115. putreal(s)
  116. char    *s;
  117. {
  118. union
  119. {
  120.         double  num;
  121.         unsigned char   n[8];
  122. } cludge;
  123.  
  124.         cludge.num = atof(s);
  125.         *ptree_ptr++ = cludge.n[0];
  126.         *ptree_ptr++ = cludge.n[1];
  127.         *ptree_ptr++ = cludge.n[2];
  128.         *ptree_ptr++ = cludge.n[3];
  129.         *ptree_ptr++ = cludge.n[4];
  130.         *ptree_ptr++ = cludge.n[5];
  131.         *ptree_ptr++ = cludge.n[6];
  132.         *ptree_ptr++ = cludge.n[7];
  133. }
  134.  
  135. /* supplied by KMW */
  136.  
  137. yyerror (s)
  138. char *s;
  139. {
  140.     fprintf (stderr, "%s\n", s);
  141. }
  142.